package pwd.allen.construct.flyweight;

import pwd.allen.construct.common.IConnection;

/**
 * 具体享元角色
 * @author lenovo
 * @create 2021-05-21 16:39
 **/
public class ConcreteFlyWeight implements IFlyWeight {

    private String host;
    private int port;
    private String dbName;

    /**
     * key格式为：host:port/dbName
     * @param key
     */
    public ConcreteFlyWeight(String key) {
        String[] split = key.split("/|:");
        this.host = split[0];
        this.port = Integer.parseInt(split[1]);
        this.dbName = split[2];
    }

    @Override
    public void operation(IConnection connection) {
        connection.pingConnection(host, port, dbName);
    }
}
